package yto.freemarker.springcloud.feign;

import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import yto.freemarker.springcloud.entity.User;

/**
 * @author dongxing
 * @create 2018-01-23 10:14
 **/
@Component
public class UserFeignClientFallbackFactory implements FallbackFactory<UserFeignClient> {
    Logger LOGGER = LoggerFactory.getLogger(UserFeignClientFallbackFactory.class);

    @Override
    public UserFeignClient create(Throwable throwable) {
        LOGGER.info("异常的信息:{}", throwable.getMessage());
        return id -> {
            User user = new User();
            user.setId(-1L);
            user.setUsername("失败的请求");
            return user;
        };
    }
}
